package mobile;

import java.util.HashMap;
import java.util.Map;

import mda.type.IGallery;
import mda.type.IListPage;
import mda.type.IMainPage;
import mda.type.IMixedPage;
import mda.type.IOverlayPage;
import mda.type.ITextPage;
import mda.type.ITimeTablePage;
import flca.mda.codegen.CodegenConstants;
import flca.mda.codegen.data.TemplateMergeStrategy;

public class MobileConstants
{
	public static final String CARTRIDGE_NAME = "mobile";

	public TidMobile[] getTemplates()
	{
		return TidMobile.values();
	}

	//----------------- several maps with TemplateId as the key and template property as the value
	
	private static Map<TidMobile, String> sJetFiles;
	private static Map<TidMobile, Class<?>[]> sAppliesTo;
	private static Map<TidMobile, String> sGeneratorFqn;

	private static final String CLSNAME = "<%=" + CodegenConstants.CLASSNAME + "%>";
	private static final String Frontend = "<%=" + "Frontend-Mobile" + "%>";
	
	static {
		sJetFiles = new HashMap<TidMobile, String>();
		
		sJetFiles.put(TidMobile.MOB_MAIN_HTML, 		"/mobile/MobMainHtml.jet");
		sJetFiles.put(TidMobile.MOB_MAIN_CSS, 		"/mobile/MobMainCss.jet");
		sJetFiles.put(TidMobile.MOB_OVERLAY_CSS, 	"/mobile/MobOverlayCss.jet");
		sJetFiles.put(TidMobile.MOB_OVERLAY_HTML, 	"/mobile/MobOverlayHtml.jet");
		sJetFiles.put(TidMobile.MOB_TEXT_HTML, 		"/mobile/MobTextHtml.jet");
		sJetFiles.put(TidMobile.MOB_MIXED_CSS, 		"/mobile/MobMixedCss.jet");
		sJetFiles.put(TidMobile.MOB_MIXED_HTML, 	"/mobile/MobMixedHtml.jet");
		sJetFiles.put(TidMobile.MOB_LIST_HTML, 		"/mobile/MobListHtml.jet");
		sJetFiles.put(TidMobile.MOB_GALLERY_HTML, 	"/mobile/MobGalleryHtml.jet");
		sJetFiles.put(TidMobile.MOB_TIMESLOTS_HTML,	"/mobile/MobTimeSlotsHtml.jet");
		sJetFiles.put(TidMobile.MOB_TIMESLOTS_CSS, 	"/mobile/MobTimeSlotsCss.jet");
	}
	
	static {
		sGeneratorFqn = new HashMap<TidMobile, String>();
		
		sGeneratorFqn.put(TidMobile.MOB_MAIN_HTML, 		MobMainHtml.class.getName());
		sGeneratorFqn.put(TidMobile.MOB_MAIN_CSS, 		MobMainCss.class.getName());
		sGeneratorFqn.put(TidMobile.MOB_OVERLAY_CSS, 	MobOverlayCss.class.getName());
		sGeneratorFqn.put(TidMobile.MOB_OVERLAY_HTML, 	MobOverlayHtml.class.getName());
		sGeneratorFqn.put(TidMobile.MOB_TEXT_HTML, 		MobTextHtml.class.getName());
		sGeneratorFqn.put(TidMobile.MOB_MIXED_CSS, 		MobMixedCss.class.getName());
		sGeneratorFqn.put(TidMobile.MOB_MIXED_HTML, 	MobMixedHtml.class.getName());
		sGeneratorFqn.put(TidMobile.MOB_LIST_HTML, 		MobListHtml.class.getName());
		sGeneratorFqn.put(TidMobile.MOB_GALLERY_HTML, 	MobGalleryHtml.class.getName());
		sGeneratorFqn.put(TidMobile.MOB_TIMESLOTS_HTML, MobTimeSlotsHtml.class.getName());
		sGeneratorFqn.put(TidMobile.MOB_TIMESLOTS_CSS, 	MobTimeSlotsCss.class.getName());
	}
	
	static {
		sAppliesTo = new HashMap<TidMobile, Class<?>[]>();
		
		sAppliesTo.put(TidMobile.MOB_MAIN_HTML, 	new Class<?>[] { IMainPage.class });
		sAppliesTo.put(TidMobile.MOB_MAIN_CSS, 		new Class<?>[] { IMainPage.class });
		sAppliesTo.put(TidMobile.MOB_OVERLAY_CSS, 	new Class<?>[] { IOverlayPage.class });
		sAppliesTo.put(TidMobile.MOB_OVERLAY_HTML, 	new Class<?>[] { IOverlayPage.class });
		sAppliesTo.put(TidMobile.MOB_TEXT_HTML, 	new Class<?>[] { ITextPage.class });
		sAppliesTo.put(TidMobile.MOB_MIXED_CSS, 	new Class<?>[] { IMixedPage.class });
		sAppliesTo.put(TidMobile.MOB_MIXED_HTML, 	new Class<?>[] { IMixedPage.class });
		sAppliesTo.put(TidMobile.MOB_LIST_HTML, 	new Class<?>[] { IListPage.class });
		sAppliesTo.put(TidMobile.MOB_GALLERY_HTML, 	new Class<?>[] { IGallery.class });
		sAppliesTo.put(TidMobile.MOB_TIMESLOTS_HTML,	new Class<?>[] { ITimeTablePage.class });
		sAppliesTo.put(TidMobile.MOB_TIMESLOTS_CSS, 	new Class<?>[] { ITimeTablePage.class });
	}
	
	

	//--------- static getters ---
	
	public static String getJetFile(TidMobile aTemplateId)
	{
		if (sJetFiles.containsKey(aTemplateId)) {
			return sJetFiles.get(aTemplateId);
		} else {
			throw new RuntimeException("no jetfile found for " + aTemplateId);
		}
	}
	
	public static String getFileExt(TidMobile aTemplateId)
	{
		if (aTemplateId.name().endsWith("CSS")) {
			return ".css";
		} else {
			return ".html";
		}
	}
	
	public static String getClassname(TidMobile aTemplateId)
	{
		return CLSNAME;
	}

	public static String getGeneratorFqn(TidMobile aTemplateId)
	{
		if (sGeneratorFqn.containsKey(aTemplateId)) {
			return sGeneratorFqn.get(aTemplateId);
		} else {
			throw new RuntimeException("no generatorFqn found for " + aTemplateId);
		}
	}


	public static TemplateMergeStrategy getMergeStrategy(TidMobile aTemplateId)
	{
		return TemplateMergeStrategy.SIMPLE_MERGE;
	}
	
	public static Class<?>[] getAppliesTo(TidMobile aTemplateId)
	{
		if (sAppliesTo.containsKey(aTemplateId)) {
			return sAppliesTo.get(aTemplateId);
		} else {
			throw new RuntimeException("no targetdir found for " + aTemplateId);
		}
	}

	public static String getPackage(TidMobile aTemplateId)
	{
		return "<%=" + CodegenConstants.PACKAGE + "%>" ;
	}

	private static final String SRC_GEN = "assets";

	public static String getTargetDir(TidMobile aTemplateId)
	{
		return Frontend + "/<%=" + SRC_GEN + "%>";
	}
	
	public static int getRank(TidMobile aTemplateId)
	{
		if (aTemplateId.name().indexOf("MAIN") > 0) {
			return 2;
		} else {
			return 5;
		}
	}
}



